package com.lxj.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * TestJdbc3
 */
public class TestJdbc3 {

    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
            e.printStackTrace();
        }

        try (
            Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/how2java?charactorEncoding=UTF-8", "root", "root");
            Statement s = c.createStatement();
        ) {

            
            c.setAutoCommit(false);

            String sql1 = "update hero set hp = hp+1 where id = 22 ";
            s.execute(sql1);

            // 减少血量
            String sql2 = "updata hero set hp = hp-1 where id = 22";
            s.execute(sql2);

            c.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}